require "Common/define"
require "Logic/Config"
require "Common/functions"
require "View/CharactorUI/UICharactorInfoHeroBreak"
require "View/CharactorUI/UIBreakStone"

UICharactorInfoHero = {};
HelperFunc.SetUIEnv(UICharactorInfoHero)
local this = UICharactorInfoHero;

---@type FairyGUI.GComponent
this.gameObject = nil;
this.transform = nil;
this.LuaBehaviour = nil;
this.hasInit = false;

local firstCache = false

this.currentHeroData = nil; --当前英雄信息
this.isShowModel = false;
this.cacheIsShowModel = isShowModel;
this.callBackId = nil;
this.modelAnimDuration = 0;
this.allHero = {};
this.startDragPosX = nil;
---@type FairyGUI.GoWrapper
this.drawWrapper = {};
---@type GameObject[]
this.objModel = {}
---@type GGraph[]
this.graphicList = {}
this.btnPreviewBack = nil; --退出预览模式
---@type FairyGUI.GButton
this.btnDrag = nil;

this.canvasRect = nil;

---@type FairyGUI.GLoader
this.iconProfession = nil; --职业
this.textTitleName = nil; --称号
this.textHeroName = nil; --名字

---@type FairyGUI.GButton
this.btnInfo = nil; --属性
this.btnSkill = nil; --技能
this.btnEquip = nil; -- 装备
this.btnBreak = nil; -- 突破
this.btnWeapon = nil; --专武
this.btnFavor = nil;  --好感度

this.btnBack = nil;
this.btnLeftSwitch = nil;
this.btnRightSwitch = nil;
this.btnArchives = nil; --档案
this.btnCombination = nil;--羁绊
this.btnShop = nil; --快捷购买
this.hasAddRedDots = false;

--可隐藏标签页
---@type FairyGUI.Controller
this.ctrlShowBigDraw = nil;
this.ctrlBottom = nil
this.btnModelSwitch = nil;
this.btnPreview = nil;

this.txtPowerSpine = nil
this.txtPower = nil;
this.gameObjectName = nil
this.rootObj = nil
this.isExit = nil
-- this.gameObjectTable = {}
this.cur_show_model1 = nil
this.cur_show_model2 = nil
this.objHeroModel = nil
this.objDrawModel = nil

this.curShowSubPanelName = nil;
this.qualityFrame = nil
this.qualityIcon = nil
this.qualityNumIcon = nil
this.idleTimer = nil;
this.lasTabState = nil
this.staegeController = nil;
this.maxController = nil;
this.modeShowController = nil;
this.bg = nil;
this.skinBtn = nil;
this.btnAward = nil;
this.startPos = {};
this.heroType = nil
this.dragobj = nil
this.dragX = nil
this.dragY = nil
this.orPosX = nil
this.orPosY = nil
this.touchCount = 0
this.touchDistance = nil
this.effFire1 = nil;
this.effFire2 = nil;
this.effFire1Obj = nil;
this.effFire2Obj = nil;
this.effDrawWrapper1 = nil;
this.effDrawWrapper2 = nil;
this.typeName = { "New_occupation_3", "New_occupation_5", "New_occupation_6", "New_occupation_2", "New_occupation_4", "New_occupation_1" };
--技能
this.skillObj = nil

this.gameObject = nil;
this.transform = nil;
this.LuaBehaviour = nil;

this.hasInit = false;

this.trickGroup = {};
this.specialGroup = {};
this.specialTwoGroup = {};
this.passiveGroup = {};
this.skill5Group = {}
this.level = nil
this.isPlaySkillEffect = nil
this.breakCtrl = {}
this.showIconList = {};
this.showIconHeadPosBtn = nil;
this.showIconHandPosBtn = nil;
this.showIconLegPosBtn = nil;
this.showIconBodyPosBtn = nil;
this.showIconWeaponBtn = nil;
this.showIconInlaylinkBtn = nil;
this.showIconStateCtrl = nil;
this.switchStateBtn = nil;
this.btnFavorHelp = nil;
this.fadeTimeId = nil
this.fadeTimeIdNext = nil
this.drawIndex = 1
this.setFadeTimeId = nil
this.heroManorCtrl = nil
this.btnManor = nil
local drawMat = nil
--对应FGUI cbottom的下表
local ButtonType = {
    Attr = 0, --属性
    Equip = 1, --装备
    Skill = 2, --技能
    Break = 3, --突破
    Weapon = 4, --专武
    Favor = 5, --好感度
    Rune = 6, --符文
}
local ModelType = {
    Draw = 1, --原画
    hero = 2, --spine动画
    Draw2 = 3,--动画切换
}
local firstCache = false

local initIndex = 0;
local isSetFade = nil
---@type FairyGUI.GList
-- local AffectGrid;//策划 卢晓飞 确认过 角色定位 功能已经没有了 add by dingzhichao
function UICharactorInfoHero.Init(heroData, index, showOneHero, callfun, type, jumpFun, sortType,isFade)
    --todo 应该小写 暂时先大写
    local name, package = getUIName(PanelNames.UICharactorInfoHero);
    currentHeroData = heroData;
    this.isShowOneHero = showOneHero;
    this.callback = callfun;
    heroType = type
    this.jumpFun = jumpFun
    this.tabOwner = {};
    allHero = {};
    local tempOwner = logicMgr.HeroManager.getOwnerHeroList(nil, heroType);
    local tempHeroLink = {};
    if logicMgr.FuncOpenManager.isOpen(Config.FuncOpenType.HeroLink) and not logicMgr.HeroLinkManager.IsTopLevelOpen() then
        tempHeroLink = logicMgr.HeroLinkManager.getMainList();
        for i = 1, #tempHeroLink do
            local data = logicMgr.HeroManager.getHeroDatabyPartnerId(tempHeroLink[i]);
            if data then
                if data["type"] == type or EnumConst.HeroTypeEnum.HeroTypeAll == type then
                    table.insert(allHero, data);
                end
            end
        end
    end
    for i = 1, #tempOwner do
        if tempOwner[i]["category"] ~= 2 and tempOwner[i]["category"] ~= 3 and not logicMgr.CostManager.isExistInListByValue(tempHeroLink, tempOwner[i]["partnerId"]) then
            if tempOwner[i]["type"] == type or EnumConst.HeroTypeEnum.HeroTypeAll == type then
                table.insert(this.tabOwner, tempOwner[i]);
            end
        end
    end

    local HeroSortType = logicMgr.HeroManager.HeroSortType
    this.sortType = sortType;
    if sortType == nil then
        sortType = 1
    end
    local sort = logicMgr.HeroManager.sortHeroWithPower
    if sortType == HeroSortType.power then
        sort = logicMgr.HeroManager.sortHeroWithPower
    elseif sortType == HeroSortType.quality then
        sort = logicMgr.HeroManager.sortHeroWithQuality
    else
        sort = logicMgr.HeroManager.sortHeroWithLevel
    end
    table.sort(allHero, sort);
    table.sort(this.tabOwner, sort);
    for k, v in pairs(this.tabOwner) do
        table.insert(allHero, v);
    end

    if index ~= nil then
        initIndex = index;
    else
        initIndex = 0;
    end
    if isFade then
        isSetFade = true
    end
    panelMgr:ShowUI(name, package, this.onCreate, Config.useLocalUI);
end
---@param obj FairyGUI.GComponent
function UICharactorInfoHero.onCreate(obj)
    rootObj = obj
    gameObjectName = obj.gameObjectName
    isExit = false
    if not hasInit then
        hasInit = true;

        this.effect_shen = obj:GetChild("effect_shen");
        this.effect_mo = obj:GetChild("effect_mo");

        if this.effect_shen then
            this.effect_shen:ResetClipping();
        end
        if this.effect_mo then
            this.effect_mo:ResetClipping();
        end

        ctrlBottom = obj:GetController("cbottom")
        this.isShowOneController = obj:GetController("isShowOne")
        graphicList = { obj:GetChild("draw"), obj:GetChild("modelPos"),obj:GetChild("draw2") }
        drawWrapper = { GoWrapper.New(), GoWrapper.New(),GoWrapper.New() }
        btnPreviewBack = obj:GetChild("PreviewBackBtn");
        ctrlShowBigDraw = obj:GetController("ShowBigDraw")
        textTitleName = obj:GetChild("titleName");
        textHeroName = obj:GetChild("name");
        iconProfession = obj:GetChild("profession");
        -- AffectGrid = obj:GetChild("AffectGrid")
        btnInfo = obj:GetChild("attributeBtn");
        btnInfo.gameObjectName = "attributeBtn";
        btnSkill = obj:GetChild("skillBtn");
        btnSkill.gameObjectName = "skillBtn";
        btnEquip = obj:GetChild("EquipBtn");
        btnEquip.gameObjectName = "EquipBtn";
        btnBreak = obj:GetChild("rankBtn");
        btnBreak.gameObjectName = "rankBtn";
        btnFavor = obj:GetChild("FavorBtn")
        btnFavor.gameObjectName = "FavorBtn"
        btnWeapon = obj:GetChild("WeaponBtn");
        btnWeapon.gameObjectName = "WeaponBtn";
        btnRune = obj:GetChild("RuneBtn");
        btnRune.gameObjectName = "RuneBtn";
        skinBtn = obj:GetChild("skinBtn");
        btnAward = obj:GetChild("btn_award");
        btnAward.gameObjectName = "btn_award";
        btnBack = obj:GetChild("backBtn")
        btnLeftSwitch = obj:GetChild("before");
        btnRightSwitch = obj:GetChild("next")
        btnModelSwitch = obj:GetChild("switchBtn");
        btnPreview = obj:GetChild("previewBtn");
        btnArchives = obj:GetChild("archivesBtn");
        btnShare = obj:GetChild("btnShare");
        btnCombination = obj:GetChild("btnCombination");
        breakCtrl = obj:GetController("break")
        this.btnShop = obj:GetChild("ShopBtn");
        this.btn_comment = obj:GetChild("commentBtn")
        this.comment_num_controller = obj:GetController("CommentState")
        this.comment_num_controller:SetSelectedIndex(0)
        this.txt_comment_num = obj:GetChild("CommentNum")
        if Config.OpenCommentAndBullet then
            this.btn_comment.visible = true
        else
            this.btn_comment.visible = false
        end
        txtPower = obj:GetChild("number");
        txtPowerSpine = obj:GetChild("Spine_PowerUp")
        this.hms_graph = obj:GetChild("hms_graph")
        this.heroTips = obj:GetChild("heroTips")
        this.heroTipsType = this.heroTips:GetChild("infoType")
        this.heroTipsDescribe = this.heroTips:GetChild("name")
        this.heroTipsList = this.heroTips:GetChild("listCombination")
        this.btnShowTypeInfo = obj:GetChild("btnShowTypeInfo")
        this.heroTipsController = obj:GetController("ShowHeroTips")
        local quality = obj:GetChild("quality")
        qualityFrame = quality:GetChild("frame")
        qualityIcon = quality:GetChild("icon")
        qualityNumIcon = quality:GetChild("numIcon")
        staegeController = quality:GetController("jinjie")
        maxController = quality:GetController("LR");
        modeShowController = obj:GetController("ShowSmallPeople");
        this.raceController = obj:GetController("race");
        this.touchData = {}
        effFire1 = obj:GetChild("fire1");
        effFire2 = obj:GetChild("fire2");
        heroManorCtrl = obj:GetController("Manor");
        btnManor = obj:GetChild("btnManor");

        showIconHeadPosBtn = obj:GetChild("HeadPos");
        showIconHandPosBtn = obj:GetChild("HandPos");
        showIconLegPosBtn = obj:GetChild("LegPos");
        showIconBodyPosBtn = obj:GetChild("BodyPos");
        showIconInlaylinkBtn = obj:GetChild("inlaylink");
        showIconWeaponBtn = obj:GetChild("weapon");
        showIconStateCtrl = obj:GetController("state");
        switchStateBtn = obj:GetChild("switchStateBtn");
        this.btnFavorHelp = obj:GetChild("help5");
        showIconStateCtrl.selectedIndex = 0;
        switchStateBtn.title = getLanguage("UICharactorInfoHeroStateBtnWeapon")
        showIconList = {}
        this.creatShowIcon(showIconHeadPosBtn, EnumConst.EquipPartEnum.HEAD);
        this.creatShowIcon(showIconHandPosBtn, EnumConst.EquipPartEnum.HAND);
        this.creatShowIcon(showIconLegPosBtn, EnumConst.EquipPartEnum.LEG);
        this.creatShowIcon(showIconBodyPosBtn, EnumConst.EquipPartEnum.BODY);
        this.creatShowIcon(showIconWeaponBtn, EnumConst.EquipPartEnum.WEAPON);
        this.creatShowIcon(showIconInlaylinkBtn, EnumConst.EquipPartEnum.FRAGMENT);
        breakStone = UIBreakStone:new(quality);
        ctrlShowBigDraw.selectedIndex = 0
        bg = obj:GetChild("btndrag");
        dragobj = obj:GetChild("DragBtn")
        this.HeroLineTextController = obj:GetController("say")
        this.Txt_ActorLines = obj:GetChild("Txt_ActorLines")

        this.bloom_rt = obj:GetChild("bloom_rt");
        if this.bloom_rt then
        end
        --技能
        skillObj = obj:GetChild("Com_Skill")
        local temp = { "TrickGroup", "SpecailGroup", "SpecailTwoGroup", "PassiveGroup", "skill5" }
        for k, v in pairs(temp) do
            local tb = nil
            if k == 1 then
                tb = trickGroup
            elseif k == 2 then
                tb = specialGroup
            elseif k == 3 then
                tb = specialTwoGroup
            elseif k == 4 then
                tb = passiveGroup
            else
                tb = skill5Group
            end
            tb.btn = skillObj:GetChild(v)
            tb.icon = tb.btn:GetChild("Mask"):GetChild("Icon")
            tb.objLock = tb.btn:GetController("CtrlLock")
            tb.txtLock = tb.btn:GetChild("LockText")
            tb.objLv = tb.btn:GetController("CtrlLv")
            tb.txtLv = tb.btn:GetChild("SkillLevelText")
            tb.effectAni = tb.btn:GetChild("effect_jnjs").wrapTarget
            tb.upCtrl = tb.btn:GetController("improve")
            tb.ctrlRace = tb.btn:GetController("race")
            tb.ctrlFifthSkill = tb.btn:GetController("fifthSkill")
            tb.aniPlay = false
            if k == 3 or k == 4 then
                tb.btnSwitch = tb.btn:GetChild("SwitchBtn")
            end
        end
        this.ctrlSkillRace = skillObj:GetController("race")
        this.ctrlSkillFifth = skillObj:GetController("fifthSkill")
        resMgr:LoadModelPrefab("UIEff/ef_afm19_fire01", function(go)
            if effDrawWrapper1 == nil then
                effDrawWrapper1 = GoWrapper.New();
            end
            if (effFire1Obj ~= nil) then
                destroyImmediate(effFire1Obj);
                effFire1Obj = nil
            end
            effFire1Obj = newObject(go);
            effFire1Obj:SetActive(true)
            effDrawWrapper1:SetWrapTarget(effFire1Obj, true)
            Util.Lua_SetLocalRotationXYZ(effFire1Obj.transform, 0, 0, 0)
            Util.Lua_SetLocalPositionXYZ(effFire1Obj.transform, 0, 0, 0);
            effFire1:SetNativeObject(effDrawWrapper1)
        end)

        resMgr:LoadModelPrefab("UIEff/ef_afm19_fire01", function(go)
            if effDrawWrapper2 == nil then
                effDrawWrapper2 = GoWrapper.New();
            end
            if (effFire2Obj ~= nil) then
                destroyImmediate(effFire2Obj);
                effFire2Obj = nil
            end
            effFire2Obj = newObject(go);
            effFire2Obj:SetActive(true)
            effDrawWrapper2:SetWrapTarget(effFire2Obj, true)
            Util.Lua_SetLocalRotationXYZ(effFire2Obj.transform, 0, 0, 0)
            Util.Lua_SetLocalPositionXYZ(effFire2Obj.transform, 0, 0, 0);
            effFire2:SetNativeObject(effDrawWrapper2)
        end)
    end
    this.addEvent();
    if this.isShowOneHero then
        this.isShowOneController.selectedIndex = 1;
    else
        this.isShowOneController.selectedIndex = 0;
    end
    this.checkShowSkinBtn()
    ctrlBottom.selectedIndex = 0
    this.refreshShowIcon()
    this.refresh();
    --this.refreshView();
    if initIndex == 1 then
        this.onClickAttribute();
    elseif initIndex == 2 then
        this.onClickEquip();
    elseif initIndex == 3 then
        this.onClickSkill();
    elseif initIndex == 4 then
        this.OnClickBreak();
    elseif initIndex == 5 then
        this.onClickWeapon();
    elseif initIndex == 6 then
        this.OnClickFavor()
    else
        this.onClickAttribute();
    end
    logicMgr.FuncOpenManager.addStatusCtr(PanelNames.UICharactorInfoHero, Config.FuncOpenType.HeroEquip, btnEquip.name, btnEquip);
    this.level = logicMgr.HeroManager.getHeroShowLevelByPartnerId(currentHeroData.partnerId)
    this.refreshSkill();
    this.refreshShop();
    this.refreshManor();
    --partnerHandler.HttpGetHeroCommentData(currentHeroData.partnerModelId)
    this.UpdateCommentNum();
end

function UICharactorInfoHero.addEvent()
    btnInfo.onClick:Add(this.onClickAttribute);
    btnSkill.onClick:Add(this.onClickSkill);
    btnEquip.onClick:Add(this.onClickEquip);
    btnWeapon.onClick:Add(this.onClickWeapon);
    btnBreak.onClick:Add(this.OnClickBreak);
    btnRune.onClick:Add(this.OnClickRune)
    btnFavor.onClick:Add(this.OnClickFavor);
    btnModelSwitch.onClick:Add(this.onClickModelSwitch);
    btnPreview.onClick:Add(this.onClickPreview);
    btnBack.onClick:Add(this.onClickBack);
    btnLeftSwitch.onClick:Add(this.onClickLeftSwitch);
    btnRightSwitch.onClick:Add(this.onClickRightSwitch);
    btnArchives.onClick:Add(this.onClickArchives);
    btnCombination.onClick:Add(this.onClickCombination);
    btnPreviewBack.onClick:Add(this.onClickPreviewBack);
    bg.onTouchBegin:Add(this.OnMoveStart);
    bg.onTouchEnd:Add(this.OnEndMove);
    bg.onClick:Add(this.HeroAcyion);
    skinBtn.onClick:Add(this.FashShow);
    this.btnShowTypeInfo.onClick:Add(this.ShowHeroTips);
    rootObj.onClick:Add(this.CloseHeroTips);
    btnAward.onClick:Add(this.onClickReward)
    dragobj.onTouchMove:Add(this.HeroDragMove)
    dragobj.onTouchBegin:Add(this.HeroDragBegin)
    dragobj.onTouchEnd:Add(this.HeroDragEnd)
    dragobj.onClick:Add(this.onClickPreviewBack)
    trickGroup.btn.onClick:Add(this.onClickShowTrickSkill)
    specialGroup.btn.onClick:Add(this.onClickShowSpecialSkill)
    specialTwoGroup.btn.onClick:Add(this.onClickShowSpecialTwoSkill)
    specialTwoGroup.btnSwitch.onClick:Add(this.onClickSwitchSpecialTwo)
    passiveGroup.btn.onClick:Add(this.onClickShowPassiveSkill)
    passiveGroup.btnSwitch.onClick:Add(this.onClickShowPassiveSkill)
    skill5Group.btn.onClick:Add(this.OnClickSkill5)
    btnShare.onClick:Add(this.onClick_Share)
    this.btnShop.onClick:Add(this.onClickShop);
    switchStateBtn.onClick:Add(this.OnChangeShowIcon)
    this.btn_comment.onClick:Add(this.onClickHeroComment)
    this.btnFavorHelp.onClick:Add(this.onClickFavorHelp)
    btnManor.onClick:Add(this.onClick_Manor)
end

function UICharactorInfoHero.onClickHeroComment()
    this.checkStopVoice()
    AudioManager.Play(AudioManager.Play_UI_Hero_File_Page)
    showUI(PanelNames.UICharactorInfoArchives, currentHeroData, 2);
end

function UICharactorInfoHero.HeroDragBegin(evt)
    touchCount = Stage.inst.touchCount
    local id = evt.inputEvent.touchId
    local data = this.touchData[id]
    if not data then
        data = TablePool.Get()
        this.touchData[id] = data
    end
    data.id = id
    data.startX = evt.inputEvent.x
    data.startY = evt.inputEvent.y
    data.x = data.startX
    data.y = data.startY
    data.oldX = data.startX
    data.oldY = data.startY
    touchDistance = 0
end
function UICharactorInfoHero.HeroDragMove(evt)
    local id = evt.inputEvent.touchId
    local data = this.touchData[id]
    if data == nil then
        return
    end
    data.oldX = data.x
    data.oldY = data.y
    data.x = evt.inputEvent.x
    data.y = evt.inputEvent.y
    if touchCount == 1 then
        dragX = data.oldX
        dragY = data.oldY
        local posx, posy = graphicList[this.drawIndex].x, graphicList[this.drawIndex].y
        local tempX = evt.inputEvent.x - dragX
        local tempY = evt.inputEvent.y - dragY
        dragX = evt.inputEvent.x
        dragY = evt.inputEvent.y
        local endPosx = posx + tempX
        local endPosy = posy + tempY
        endPosx = math.max(endPosx, 0)
        endPosx = math.min(endPosx, 1080)
        endPosy = math.max(endPosy, -50)
        endPosy = math.min(endPosy, 2000)
        graphicList[this.drawIndex].x = endPosx
        graphicList[this.drawIndex].y = endPosy
    else
        if id ~= 1 then
            return
        end
        local data1 = this.touchData[0]
        local data2 = this.touchData[1]
        if data1 == nil or data2 == nil then
            return
        end

        local dx = data1.x - data2.x
        local dy = data1.y - data2.y
        local distance = math.abs(dx) + math.abs(dy)  --开根号费性能
        if touchDistance == 0 then
            touchDistance = distance
            return
        end
        local temp = (distance - touchDistance) * 0.001
        touchDistance = distance
        local scale = graphicList[this.drawIndex].scaleX + temp
        scale = math.max(scale, 1)
        scale = math.min(scale, 1.5)
        graphicList[this.drawIndex].scaleX = scale
        graphicList[this.drawIndex].scaleY = scale
    end
end
function UICharactorInfoHero.HeroDragEnd(evt)
    local id = evt.inputEvent.touchId
    local data = this.touchData[id]
    if data then
        this.touchData[id] = nil
        TablePool.Release(data)
    end
end
function UICharactorInfoHero.SetPosData(evt)
    local x1, y1, x2, y2
    if evt.inputEvent.touchId == 0 then
        x1 = evt.inputEvent.x
        y1 = evt.inputEvent.y
    else
        x2 = evt.inputEvent.x
        y2 = evt.inputEvent.y
    end
    local distance = math.sqrt(math.abs(x1 * x1 + y1 * y1 - x2 * x2 - y2 * y2))
    return distance
end
function UICharactorInfoHero.removeEvent()
    btnInfo.onClick:Clear()
    btnSkill.onClick:Clear()
    btnEquip.onClick:Clear()
    btnWeapon.onClick:Clear()
    btnBreak.onClick:Clear()
    btnRune.onClick:Clear()
    btnFavor.onClick:Clear()
    btnModelSwitch.onClick:Clear()
    btnPreview.onClick:Clear()
    btnBack.onClick:Clear()
    btnLeftSwitch.onClick:Clear()
    btnRightSwitch.onClick:Clear()
    btnArchives.onClick:Clear()
    btnPreviewBack.onClick:Clear()
    bg.onTouchBegin:Clear();
    bg.onTouchEnd:Clear()
    bg.onClick:Clear();
    skinBtn.onClick:Clear();
    rootObj.onClick:Clear();
    btnAward.onClick:Clear()
    dragobj.onClick:Clear()
    dragobj.onTouchBegin:Clear()
    dragobj.onTouchMove:Clear()
    this.btnShowTypeInfo.onClick:Clear();
    trickGroup.btn.onClick:Remove(this.onClickShowTrickSkill)
    specialGroup.btn.onClick:Remove(this.onClickShowSpecialSkill)
    specialTwoGroup.btn.onClick:Remove(this.onClickShowSpecialTwoSkill)
    specialTwoGroup.btnSwitch.onClick:Remove(this.onClickSwitchSpecialTwo)
    passiveGroup.btn.onClick:Remove(this.onClickShowPassiveSkill)
    passiveGroup.btnSwitch.onClick:Remove(this.onClickShowPassiveSkill)
    skill5Group.btn.onClick:Clear()
    switchStateBtn.onClick:Clear();
    this.btn_comment.onClick:Clear()
    this.btnShop.onClick:Clear();
    this.btnFavorHelp.onClick:Clear();
    btnManor.onClick:Clear();
end

function UICharactorInfoHero.LocalListenEvent()
    ListenEvent(Config.EventType.Fresh_Star, this.reGetData);
    ListenEvent(Config.EventType.Fresh_Level, this.reGetData);
    ListenEvent(Config.EventType.Fresh_Equip, this.reGetData);
    ListenEvent(Config.EventType.Fresh_HeroLink, this.reGetData);
    ListenEvent(Config.EventType.Fresh_Fragment, this.reGetData);
    ListenEvent(Config.EventType.Fresh_Handbook, this.refreshReward);
    ListenEvent(Config.EventType.Fresh_Effect_Level, this.RefreshEffectSpine)
    ListenEvent(Config.EventType.Fresh_Equip, this.RefreshEffectSpine);
    ListenEvent(Config.EventType.ReFreshHeroPower, this.freshPower);
    ListenEvent(Config.EventType.Update_Weapon, this.refreshModel);
    ListenEvent(Config.EventType.Reset_Weapon, this.refreshModel);
    ListenEvent(Config.EventType.Click_HeroSkill, this.playSkillAction);
    ListenEvent(Config.EventType.Fresh_Skill, this.reSkillGetData)
    ListenEvent(Config.EventType.Fresh_Star, this.reSkillGetData)
    ListenEvent(Config.EventType.Fresh_HandbookRewardSuc, this.Fresh_HandbookRewardSuc)
    ListenEvent(Config.EventType.WearNewSkin, this.wearNewSkin)
    ListenEvent(Config.EventType.SkinChange, this.wearNewSkin)
    ListenEvent(Config.EventType.ChangeLayer, this.ChangeLayer)
    ListenEvent(Config.EventType.HeroWeapon_LevelUp, this.refreshSkill)
    ListenEvent(Config.EventType.FreshManorInfo, this.refreshManor)
end

function UICharactorInfoHero.LocalCloseEvent()
    CloseEvent(Config.EventType.Fresh_Star, this.reGetData);
    CloseEvent(Config.EventType.Fresh_Level, this.reGetData);
    CloseEvent(Config.EventType.Fresh_Equip, this.reGetData);
    CloseEvent(Config.EventType.Fresh_HeroLink, this.reGetData);
    CloseEvent(Config.EventType.Fresh_Fragment, this.reGetData);
    CloseEvent(Config.EventType.Fresh_Handbook, this.refreshReward);
    CloseEvent(Config.EventType.Fresh_Effect_Level, this.RefreshEffectSpine)
    CloseEvent(Config.EventType.Fresh_Equip, this.RefreshEffectSpine);
    CloseEvent(Config.EventType.ReFreshHeroPower, this.freshPower);
    CloseEvent(Config.EventType.Update_Weapon, this.refreshModel);
    CloseEvent(Config.EventType.Reset_Weapon, this.refreshModel);
    CloseEvent(Config.EventType.Click_HeroSkill, this.playSkillAction);
    UIRedDots.removeViewEvent(PanelNames.UICharactorInfoHero)
    CloseEvent(Config.EventType.Fresh_Skill, this.reSkillGetData)
    CloseEvent(Config.EventType.Fresh_Star, this.reSkillGetData)
    CloseEvent(Config.EventType.Fresh_HandbookRewardSuc, this.Fresh_HandbookRewardSuc)
    CloseEvent(Config.EventType.WearNewSkin, this.wearNewSkin)
    CloseEvent(Config.EventType.SkinChange, this.wearNewSkin)
    CloseEvent(Config.EventType.ChangeLayer, this.ChangeLayer)
    CloseEvent(Config.EventType.HeroWeapon_LevelUp, this.refreshSkill)
    logicMgr.FuncOpenManager.removeStatusCtr(PanelNames.UICharactorInfoHero);
    CloseEvent(Config.EventType.FreshManorInfo, this.refreshManor)
end

function UICharactorInfoHero.reSkillGetData(msg)
    if msg then
        isPlaySkillEffect = true
    end
    if currentHeroData ~= nil then
        currentHeroData = logicMgr.HeroManager.getHeroDatabyPartnerId(tostring(currentHeroData["partnerId"]), true);
        this.level = logicMgr.HeroManager.getHeroShowLevelByPartnerId(currentHeroData.partnerId)
        this.refreshSkill();
    end
end

function UICharactorInfoHero.refreshSkill()
    Util.SetPlayerPrefs(logicMgr.HeroManager.GetRoleInfo().playerId .. Config.EventType.Fresh_HeroSkill .. currentHeroData.partnerModelId, 0);
    FireEvent(Config.EventType.Fresh_HeroSkill);
    local skillInfos = logicMgr.SkillManager.getSkillInfosById(currentHeroData.partnerModelId);
    this.refreshSkillIcon(skillInfos[EnumConst.SkillFieldType.Trick], trickGroup);
    this.refreshSkillIcon(skillInfos[EnumConst.SkillFieldType.Speical], specialGroup);
    this.refreshSkillIcon(skillInfos[EnumConst.SkillFieldType.SpecialTwo], specialTwoGroup);
    this.refreshSkillIcon(skillInfos[EnumConst.SkillFieldType.Passive], passiveGroup);
    this.refreshSkillIcon(skillInfos[EnumConst.SkillFieldType.skill5], skill5Group, EnumConst.SkillFieldType.skill5);
    this.ctrlSkillRace.selectedIndex = currentHeroData.faction
    if skillInfos[EnumConst.SkillFieldType.skill5] then
        this.ctrlSkillFifth.selectedIndex = 1
    else
        this.ctrlSkillFifth.selectedIndex = 0
    end
end

function UICharactorInfoHero.refreshSkillIcon(skillInfoItem, curGroup, index)
    if skillInfoItem == nil then
        curGroup["skill"] = nil;
        curGroup["level"] = 0;
        curGroup["btn"].visible = false
        return ;
    end
    local weaponData = logicMgr.EquipManager.tabWeapon[tostring(currentHeroData.partnerId)];
    local weaponLv = 0
    if weaponData then
        weaponLv = weaponData.level
        if weaponLv == 0 then
            weaponLv = 1
        end
    end

    local skillInfo = dataTable.getDataTable("t_weaponskill")[150000 + tonumber(currentHeroData.partnerModelId)][math.ceil(weaponLv / 20) * 20]
    if skillInfo and skillInfo.f_WeaponSkill == skillInfoItem.f_SkillList[1] then
        if weaponLv >= 20 then
            curGroup.upCtrl.selectedIndex = math.floor(weaponLv / 20)
        else
            curGroup.upCtrl.selectedIndex = 0
        end
    else
        curGroup.upCtrl.selectedIndex = 0
    end
    curGroup["btn"].visible = true
    local curLv = logicMgr.SkillManager.getSkillLv(skillInfoItem, this.level, currentHeroData.quality); --当前等级

    if curGroup.partnerId == currentHeroData.partnerId and curGroup.level < curLv then
        AudioManager.Play(2024)
    end

    curGroup["skill"] = skillInfoItem;
    curGroup["level"] = curLv;
    curGroup.partnerId = currentHeroData.partnerId
    local unlock = curLv > 0;
    curGroup.objLock:SetSelectedIndex(not unlock and 1 or 0)
    curGroup.objLv:SetSelectedIndex(unlock and 1 or 0)
    if curLv > 0 then
        if isPlaySkillEffect and ((not curGroup.aniPlay) or (curGroup.aniPlay and curGroup.aniPlay ~= curLv)) then
            Util.PlayAction(curGroup.effectAni, "idle", false)
        end
        curGroup.aniPlay = curLv
        curGroup.txtLv.text = tostring(curLv);
    else
        curGroup.aniPlay = false
        local t_skillunlocker_item = G.dataTable["t_skillunlocker"][tostring(skillInfoItem.f_SkillID)]
        if t_skillunlocker_item ~= nil then
            local limitLv = t_skillunlocker_item.f_SkillUnlocker
            if limitLv > this.level then
                curGroup.txtLock.text = string.format(getLanguage("Sys_UnlockHeroRank"), limitLv);
            else
                curGroup.txtLock.text = string.format("(%s解锁)", getLanguage("Sys_Quality" .. t_skillunlocker_item.f_SkillRelease / 10));
            end
        else
            print("@策划:解锁技能id不存在t_skillunlocker f_SkillID:", skillInfoItem.f_SkillID)
        end
    end
    if curGroup["btnSwitch"] ~= nil then
        curGroup.btnSwitch.visible = false
    end

    local iconName = tostring(skillInfoItem["f_SkillIcon"]);
    curGroup.icon.url = "ui://SkillAtlas/" .. iconName
    if index == EnumConst.SkillFieldType.skill5 then
        local faction = currentHeroData.faction
        if faction == 1 or faction == 2 or faction == 3 then
            curGroup.ctrlRace.selectedIndex = faction
            curGroup.ctrlFifthSkill.selectedIndex = 1
        else
            curGroup.ctrlRace.selectedIndex = 0
        end
    end
end

function UICharactorInfoHero.ChangeLayer(msg)
    local layerNmme = "mapBeijing"
    if msg then
        layerNmme = "Default"
    end
    Util.SetOrderType(trickGroup.btn.displayObject.gameObject, layerNmme);
    Util.SetOrderType(specialGroup.btn.displayObject.gameObject, layerNmme);
    Util.SetOrderType(specialTwoGroup.btn.displayObject.gameObject, layerNmme);
    Util.SetOrderType(passiveGroup.btn.displayObject.gameObject, layerNmme);
    Util.SetOrderType(skill5Group.btn.displayObject.gameObject, layerNmme);

end

function UICharactorInfoHero.onClickShowTrickSkill()
    if trickGroup["skill"] ~= nil then
        this.ChangeLayer()
        showUI(PanelNames.UICharactorInfoHeroSkillDetailsNew, trickGroup["skill"], trickGroup["level"], this.currentHeroData["partnerModelId"]);
        --FireEvent(Config.EventType.Click_HeroSkill, trickGroup["skill"].f_SkillID)
        AudioManager.PlayInteractionVoice(this.currentHeroData["partnerModelId"], 0, AudioManager.InteractionTagTable[12].Tag)
    end
end

function UICharactorInfoHero.onClickShowSpecialSkill()
    if specialGroup["skill"] ~= nil then
        this.ChangeLayer()
        showUI(PanelNames.UICharactorInfoHeroSkillDetailsNew, specialGroup["skill"], specialGroup["level"], this.currentHeroData["partnerModelId"]);
        --FireEvent(Config.EventType.Click_HeroSkill, specialGroup["skill"].f_SkillID)
        AudioManager.PlayInteractionVoice(this.currentHeroData["partnerModelId"], 0, AudioManager.InteractionTagTable[13].Tag)
    end
end

function UICharactorInfoHero.onClickShowSpecialTwoSkill()
    if specialTwoGroup["skill"] ~= nil then
        this.ChangeLayer()
        showUI(PanelNames.UICharactorInfoHeroSkillDetailsNew, specialTwoGroup["skill"], specialTwoGroup["level"], this.currentHeroData["partnerModelId"]);
        --FireEvent(Config.EventType.Click_HeroSkill, specialTwoGroup["skill"].f_SkillID)
        AudioManager.PlayInteractionVoice(this.currentHeroData["partnerModelId"], 0, AudioManager.InteractionTagTable[14].Tag)
    end
end

function UICharactorInfoHero.onClickSwitchSpecialTwo()
    if #logicMgr.SkillManager.getImitationSkillInfos(EnumConst.SkillFieldType.SpecialTwo) > 0 then
        showUI(PanelNames.UICharactorInfoHeroSkillSelect, specialTwoGroup["skill"], EnumConst.SkillFieldType.SpecialTwo);
        AudioManager.PlayInteractionVoice(this.currentHeroData["partnerModelId"], 0, AudioManager.InteractionTagTable[14].Tag)
    else
        UISysTips.AddMsg(getLanguage("Sys_MsgUnableMocking"));
    end
end

function UICharactorInfoHero.onClickShowPassiveSkill()
    if passiveGroup["skill"] then
        this.ChangeLayer()
        showUI(PanelNames.UICharactorInfoHeroSkillDetailsNew, passiveGroup["skill"], passiveGroup["level"], this.currentHeroData["partnerModelId"]);
        --FireEvent(Config.EventType.Click_HeroSkill, passiveGroup["skill"].f_SkillID)
        AudioManager.PlayInteractionVoice(this.currentHeroData["partnerModelId"], 0, AudioManager.InteractionTagTable[15].Tag)
    else
        UISysTips.AddMsg(getLanguage("Sys_MsgUnableMocking"));
    end
end
function UICharactorInfoHero.OnClickSkill5()
    if skill5Group["skill"] then
        this.ChangeLayer()
        showUI(PanelNames.UICharactorInfoHeroSkillDetailsNew, skill5Group["skill"], skill5Group["level"], this.currentHeroData["partnerModelId"]);
        --FireEvent(Config.EventType.Click_HeroSkill, passiveGroup["skill"].f_SkillID)
        AudioManager.PlayInteractionVoice(this.currentHeroData["partnerModelId"], 0, AudioManager.InteractionTagTable[15].Tag)
    else
        UISysTips.AddMsg(getLanguage("Sys_MsgUnableMocking"));
    end
end

function UICharactorInfoHero.onClickSwitchPassive()
    if #logicMgr.SkillManager.getImitationSkillInfos(EnumConst.SkillFieldType.Passive) > 0 then
        showUI(PanelNames.UICharactorInfoHeroSkillSelect, passiveGroup["skill"], EnumConst.SkillFieldType.Passive);
        AudioManager.PlayInteractionVoice(this.currentHeroData["partnerModelId"], 0, AudioManager.InteractionTagTable[15].Tag)
    else
        UISysTips.AddMsg(getLanguage("Sys_MsgUnableMocking"));
    end
end

function UICharactorInfoHero.onClick_Share()
    showUI(PanelResNames.UIShareHero, { hero = this.currentHeroData, type = 1 })
end

function UICharactorInfoHero.refreshShop()
    this.btnShop.visible = false;
    local actState = logicMgr.CostManager.getFastConsumption();
    if actState == 0 or (actState == 1 and logicMgr.CostManager.isFastConsumptionItems(1)) then
        if not this.hasAddRedDots and actState == 0 then
            this.hasAddRedDots = true;
            UIRedDots.addViewListen(PanelNames.UICharactorInfoHero, gameObjectName .. this.btnShop.gameObjectName, this.btnShop, Config.RedDotsType.CostGiftLink);
        end
        this.btnShop.visible = true;
    end
end

function UICharactorInfoHero.onClickShop()
    showUI(PanelResNames.UIGiftLink, 1);
end

function UICharactorInfoHero.OnDestroy()
    this.LocalCloseEvent();
    this.removeEvent();
    utimer.remove(this.callBackId)
    this.callBackId = nil

    if effDrawWrapper1 then
        effDrawWrapper1:Dispose()
        effDrawWrapper1 = nil
    end

    if effDrawWrapper2 then
        effDrawWrapper2:Dispose()
        effDrawWrapper2 = nil
    end

    for i = 1, #drawWrapper do
        drawWrapper[i]:Dispose()
    end
    drawWrapper = {}
end

function UICharactorInfoHero.DestroyObjList()
    breakStone:destroy();
    isExit = true
    if setFadeTimeId then
        utimer.remove(setFadeTimeId)
        setFadeTimeId = nil
    end
    if this.fadeTimeId then
        utimer.remove(this.fadeTimeId)
        this.fadeTimeId = nil
    end
    if this.fadeTimeIdNext then
        utimer.remove(this.fadeTimeIdNext)
        this.fadeTimeIdNext = nil
    end
    if this.cur_show_model1 ~= nil then
        destroyImmediate(this.cur_show_model1)
        this.cur_show_model1 = nil
        objModel[ModelType.hero] = nil
    end
    if objHeroModel ~= nil then
        destroy(objHeroModel);
        objHeroModel = nil
    end
    if this.cur_show_model2 ~= nil then
        if drawMat then
            this.cur_show_model2:GetComponent("SkeletonGraphic").material = drawMat
        end
        destroyImmediate(this.cur_show_model2)
        this.cur_show_model2 = nil
        objModel[ModelType.Draw] = nil
        objModel[ModelType.Draw2] = nil
    end
    objModel = {}
end

function UICharactorInfoHero.OnEnable()
    this.LocalListenEvent();
    HeroManager.ClerPool()
end

function UICharactorInfoHero.OnDisable()
    if staegeController then
        staegeController.selectedIndex = 0;
    end
    if maxController then
        maxController.selectedIndex = 0;
    end
    this.LocalCloseEvent();
    this.openSubPanel(nil);
    HeroManager.ClerPool()
    this.DestroyObjList()
    this.checkStopVoice()
    this.hasAddRedDots = false;

    FireEvent(Config.EventType.ReFreshHeroPower)
    FireEvent(Config.EventType.Fresh_Level)
end

function UICharactorInfoHero.reGetData(msg)
    if currentHeroData ~= nil then
        currentHeroData = logicMgr.HeroManager.getHeroDatabyPartnerId(tostring(currentHeroData["partnerId"], true));
        this.refresh(msg);
        this.reSkillGetData(msg)
    end
end

function UICharactorInfoHero.refreshModel()
    if isShowModel then
        this.refreshView()
    end
end
--刷新显示是icon
function UICharactorInfoHero.refreshShowIcon()
    local equips = logicMgr.EquipManager.getHeroEquipList(currentHeroData.partnerId)
    local ctrItem = CtrlManager.GetCtrl(PanelNames.EquipItem);

    for _, v in pairs(showIconList) do
        if v.part ~= EnumConst.EquipPartEnum.WEAPON and v.part ~= EnumConst.EquipPartEnum.FRAGMENT then
            v.equip = nil
            for _, v1 in pairs(equips) do
                if v1.part == v.part then
                    v.equip = v1
                    break
                end
            end
            if ctrItem and not HelperFunc.IsNull(v.obj) then
                ctrItem.initData(v.obj, v.equip, v.equip and HeroManager.GetSuit(equips, v.equip) or 0)
            end
        elseif v.part == EnumConst.EquipPartEnum.WEAPON then
            local weaponInfo = logicMgr.EquipManager.tabWeapon[this.currentHeroData.partnerId];
            if weaponInfo then
                EquipManager.SetWeaponRectIcon(v.obj, weaponInfo, this.currentHeroData.partnerId)
            end
        elseif v.part == EnumConst.EquipPartEnum.FRAGMENT then
            local itemId = logicMgr.StrangeFragmentManager.GetCurrentEquipFragment(this.currentHeroData.partnerId)
            local controller = v.obj:GetController("c1");

            local funcConfig = G.dataTable["t_functionswitch"];
            local singleConfig = funcConfig[tostring(Config.FuncOpenType.WeaponRefine)]
            if logicMgr.FuncOpenManager.unlock_check5(singleConfig, this.currentHeroData.partnerId) then
                controller.selectedIndex = 2;
                if itemId then
                    StrangeFragmentManager.SetItemData(v.obj:GetChild("item"), itemId, false);
                    controller.selectedIndex = 0;
                end
            else
                controller.selectedIndex = 1;
            end

        end
    end
end

function UICharactorInfoHero.creatShowIcon(obj, type)
    local param = {}
    param.obj = obj;
    param.part = type;
    obj.onClick:Clear()
    if type ~= EnumConst.EquipPartEnum.WEAPON then
        obj.onClick:Add(function()
            this.onClickEquip()
        end
        )
    elseif type == EnumConst.EquipPartEnum.WEAPON then
        obj.onClick:Add(function()
            this.onClickWeapon()
        end
        )
    end
    table.insert(showIconList, param)
end

function UICharactorInfoHero.OnChangeShowIcon()
    if showIconStateCtrl.selectedIndex == 1 then
        isShowModel = false;
        switchStateBtn.title = getLanguage("UICharactorInfoHeroStateBtnWeapon")
        showIconStateCtrl.selectedIndex = 0;
    else
        isShowModel = true;
        switchStateBtn.title = getLanguage("UICharactorInfoHeroStateBtnSkill")
        showIconStateCtrl.selectedIndex = 1;
    end
    this.cacheIsShowModel = isShowModel;
    this.refreshView();
end

function UICharactorInfoHero.playSkillAction(skillId)
    --[[if modeShowController.selectedIndex == 1 then
        local skillShow = G.dataTable["t_skillshow"][tostring(skillId)];
        if skillShow then
            local actionName = Entity:GetTableValue(skillShow, "f_AnimResource");
            local model = nil
            if this.cur_model_index and this.cur_model_index == 1 then
                model = this.cur_show_model1
            elseif this.cur_model_index and this.cur_model_index == 2 then
                model = this.cur_show_model2
            end
            if model then
                this.modelAnimDuration = Util.PlayAction(model.transform:Find("Animation"):GetComponent("SkeletonAnimation"), actionName, false, -1, false, 1);
                utimer.remove(this.callBackId)
                this.callBackId = utimer.delayCall(function()
                    local model_1 = model --gameObjectTable[#gameObjectTable];
                    if model_1 then
                        Util.PlayAction(model_1.transform:Find("Animation"):GetComponent("SkeletonAnimation"), "fidle", true, -1, false, 1);
                    end
                end, this.modelAnimDuration * 1000)
            end
        end
    end--]]
end

function UICharactorInfoHero.RefreshEffectSpine()
    this.SetCtrlSipne(true)
end

function UICharactorInfoHero.SetCtrlSipne(is)
    if txtPowerSpine then
        if is then
            local aniObj = rootObj.displayObject.gameObject.transform:Find("GLoader3D/GoWrapper/zlsx_effect_SkeletonData")
            if aniObj then
                Util.PlayAction(aniObj.gameObject, "idle", false);
            end
        end
        txtPowerSpine.visible = is
    end
end

function UICharactorInfoHero.freshPower()
    --txtPower.text = getNumString(logicMgr.HeroManager.GetHeroPower(currentHeroData.partnerId))
    if not firstCache then
        partnerHandler.ReqHeroPower(0)
        firstCache = true
    end
    if txtPower then
        txtPower.text = getNumString(logicMgr.HeroManager.GetHeroPower(currentHeroData.partnerId))
    end
end

function UICharactorInfoHero.refresh(msg)
    if currentHeroData == nil then
        logError("英雄信息为空");
        return ;
    end
    this.CloseHeroTips();
    if not msg then
        if #allHero > 2 then
            UIRedDots.addViewListen(PanelNames.UICharactorInfoHero, gameObjectName .. btnRightSwitch.gameObjectName .. "R", btnRightSwitch, Config.RedDotsType.Hero, this.GetLeftORRightHeroIndex().partnerId);
            UIRedDots.addViewListen(PanelNames.UICharactorInfoHero, gameObjectName .. btnLeftSwitch.gameObjectName .. "L", btnLeftSwitch, Config.RedDotsType.Hero, this.GetLeftORRightHeroIndex(true).partnerId);
        end
        UIRedDots.addViewListen(PanelNames.UICharactorInfoHero, gameObjectName .. btnWeapon.gameObjectName, btnWeapon, Config.RedDotsType.HeroWeapon, currentHeroData.partnerId);
        UIRedDots.addViewListen(PanelNames.UICharactorInfoHero, gameObjectName .. btnEquip.gameObjectName, btnEquip, Config.RedDotsType.AllHeroWear, currentHeroData.partnerId);
        UIRedDots.addViewListen(PanelNames.UICharactorInfoHero, gameObjectName .. btnBreak.gameObjectName, btnBreak, Config.RedDotsType.HeroRank, currentHeroData.partnerId);
        UIRedDots.addViewListen(PanelNames.UICharactorInfoHero, gameObjectName .. btnAward.gameObjectName, btnAward, Config.RedDotsType.HeroHandbookReward, currentHeroData.partnerId);
        UIRedDots.addViewListen(PanelNames.UICharactorInfoHero, gameObjectName .. btnInfo.gameObjectName, btnInfo, Config.RedDotsType.HeroInfoBtn, currentHeroData.partnerId);
        UIRedDots.addViewListen(PanelNames.UICharactorInfoHero, gameObjectName .. btnFavor.gameObjectName, btnFavor, Config.RedDotsType.HeroInteraction, currentHeroData.partnerId);
        UIRedDots.addViewListen(PanelNames.UICharactorInfoHero, gameObjectName .. btnRune.gameObjectName, btnRune, Config.RedDotsType.HeroRune, currentHeroData.partnerId);
        UIRedDots.addViewListen(PanelNames.UICharactorInfoHero, gameObjectName .. btnManor.gameObjectName, btnManor, Config.RedDotsType.HeroManorAuto, currentHeroData.partnerId);
    end
    if logicMgr.HeroManager.IsHeroByModelId(currentHeroData.partnerModelId) then
        btnArchives.visible = true
        this.btn_comment.visible = true
        btnWeapon.visible = true
        logicMgr.FuncOpenManager.addStatusCtr(PanelNames.UICharactorInfoHero, Config.FuncOpenType.HeroArchive, btnArchives.name, btnArchives);
        FuncOpenManager.addStatusCtr(PanelNames.UICharactorInfoHero, Config.FuncOpenType.HeroWeapon, btnWeapon.name, btnWeapon, { heroId = currentHeroData.partnerId });
        FuncOpenManager.addStatusCtr(PanelNames.UICharactorInfoHero, Config.FuncOpenType.HeroRank, btnBreak.name, btnBreak);
        FuncOpenManager.addStatusCtr(PanelNames.UICharactorInfoHero, Config.FuncOpenType.Rune, btnRune.name, btnRune);
    else
        btnArchives.visible = false
        this.btn_comment.visible = false
        btnWeapon.visible = false
    end
    iconProfession.visible = true
    iconProfession.url = EnumConst.AtlasPath.ICONAtlas .. typeName[currentHeroData["type"]]
    this.raceController.selectedIndex = currentHeroData.faction
    textHeroName.text = currentHeroData.name;
    textTitleName.text = currentHeroData.subName;
    --if not firstCache then
    --    partnerHandler.ReqHeroPower(0)
    --    firstCache = true
    --end
    logicMgr.HeroManager.updateHeroBaseAttr(currentHeroData.partnerId,false)
    partnerHandler.ReqHeroPower(currentHeroData.partnerId,false)
    txtPower.text = getNumString(logicMgr.HeroManager.GetHeroPower(currentHeroData.partnerId))
    -- 品质
    local star = logicMgr.HeroManager.starToQuality(currentHeroData.star)
    if currentHeroData.star >= 80 then
        breakCtrl.selectedIndex = 1
    else
        breakCtrl.selectedIndex = 0
    end
    local config = G.dataTable.t_iconframe[tostring(star)]
    local isFrame = config.f_Ornaments ~= ""
    qualityFrame.visible = isFrame
    local atlas = "ui://CharactorUI/"
    if isFrame then
        qualityFrame.url = atlas .. config.f_QualityOrnaments
    end
    if config.f_QualityText ~= "" then
        qualityIcon.url = atlas .. config.f_QualityText
        staegeController.selectedIndex = 1;
    else
        staegeController.selectedIndex = 0;
    end
    local quality = tonumber(config.f_Quality);
    breakStone:setQuality(quality);
    qualityNumIcon.url = atlas .. config.f_QualityIcon
    if config.f_Id > 10 then
        staegeController.selectedIndex = 0;
        maxController.selectedIndex = star - 10;
    else
        maxController.selectedIndex = 0;
    end
    this.refreshReward();

    btnShare.visible = true
    this.refreshShowIcon();
end

function UICharactorInfoHero.SetAttahment(slotName, attachMent)
    if objModel[ModelType.hero] then
        local aniObj = objModel[ModelType.hero].transform:Find("Animation").gameObject;
        if aniObj then
            local animation = aniObj:GetComponent("SkeletonAnimation")
            if animation then
                animation.Skeleton:SetAttachment(slotName, attachMent, false)
            end
        end
    end
end

function UICharactorInfoHero.AffectItemRender(index, go)

end
function UICharactorInfoHero.refreshView(isAnim,isLeft)
    utimer.remove(this.callBackId)
    btnPreview.visible = not isShowModel;
    graphicList[this.drawIndex].visible = not isShowModel
    graphicList[ModelType.hero].visible = isShowModel
    local useSkinId = logicMgr.SkinManager.getHeroSkinId(currentHeroData.partnerModelId)
    if isShowModel then
        modeShowController.selectedIndex = 1;
        local path = HeroManager.GetHeroDrawingRolePath(currentHeroData.partnerModelId, nil, useSkinId);
        objHeroModel = objModel[ModelType.hero]
        if true then

            resMgr:LoadModelPrefab(path, function(go)
                if objModel[ModelType.hero] ~= nil then
                    objModel[ModelType.hero]:SetActive(false)
                    destroy(objModel[ModelType.hero]);
                    objModel[ModelType.hero] = nil
                end
                local model = newObject(go);
                model:SetActive(true);
                objModel[ModelType.hero] = model
                model:AddComponent(TCanvas);
                model:AddComponent(TChangeSortingOrder)
                local aniObj = model.transform:Find("Animation").gameObject;
                logicMgr.EquipManager.setWeaponSkin(aniObj, currentHeroData.partnerModelId, true);
                if drawWrapper[ModelType.hero] == nil then
                    if model then
                        destroyImmediate(model);
                        objModel[ModelType.hero] = nil;
                    end
                    return ;
                end
                drawWrapper[ModelType.hero]:SetWrapTarget(model, false)
                graphicList[ModelType.hero]:SetNativeObject(drawWrapper[ModelType.hero])
                local resize, location = logicMgr.HeroManager.GetHeroLocationResizeBySkinId(useSkinId)
                local tempPos = Vector3.New(location[3], location[4], 0);
                Util.Lua_SetLocalPositionXYZ(model.transform, tempPos.x, tempPos.y, tempPos.z)
                local tempScale = Vector3.New(resize[3], resize[4], 1);
                Util.Lua_SetLocalScaleXYZ(model.transform, tempScale.x, tempScale.y, tempScale.z)
                Util.Lua_SetLocalRotationXYZ(aniObj.transform, 0, 0, 0)
                this.cur_show_model1 = model
                this.cur_model_index = 1
                local resList = {}
                local refResList = UILoading.GetLoadModelResList()
                for i = 1, #refResList do
                    local array = string.split(refResList[i], "#")
                    if #array > 1 then
                        if array[2] == "Model" then
                            table.insert(resList, array[1])
                        end
                    end
                end
                Util.UnloadRoleCache(resList, 3)
            end, true)
        end
    else
        modeShowController.selectedIndex = 0;
        local path = HeroManager.GetHeroDrawingPath(currentHeroData.partnerModelId, nil, useSkinId);
        local index = 1
        if objModel[1] ~= nil then
            index = 3
        end
        this.drawIndex = index
        if true then
            if idleTimer ~= nil then
                idleTimer:Stop();
            end
            local tempNum = -200
            if isLeft then
                tempNum = 200
            end
            if not isAnim then
                tempNum = 0
            end
            resMgr:LoadModelPrefab(path, function(go)
                if objModel[index] ~= nil then
                    destroyImmediate(objModel[index]);
                    objModel[index] = nil
                end
                local model = newObject(go);
                model.name = path;
                model:SetActive(true);
                objModel[index] = model
                drawMat = objModel[index]:GetComponent("SkeletonGraphic").material
                model:AddComponent(TCanvas);
                drawWrapper[index]:SetWrapTarget(model, false)
                graphicList[index]:SetNativeObject(drawWrapper[index])
                local resize, location = logicMgr.HeroManager.GetHeroLocationResizeBySkinId(useSkinId)
                local tempPos = Vector3.New(location[1]-tempNum, location[2], 0)
                Util.Lua_SetLocalPositionXYZ(model.transform, tempPos.x, tempPos.y, tempPos.z)
                local tempScale = Vector3.New(resize[1], resize[2], 1);
                Util.Lua_SetLocalScaleXYZ(model.transform, tempScale.x, tempScale.y, tempScale.z);
                this.delayIdle()
                this.cur_show_model2 = model
                this.cur_model_index = 2
                if this.use_lihui_rt_layer then
                    setLayer(model, LayerMask.NameToLayer("lihui"));
                end
                if setFadeTimeId then
                    utimer.remove(setFadeTimeId)
                    setFadeTimeId = nil
                end
                --[[if isSetFade then
                    isSetFade = nil
                    local _skeletonGraphicComp = objModel[index]:GetComponent("SkeletonGraphic")
                    _skeletonGraphicComp.material = Material(Shader.Find("Unlit/rongjie"))
                    _skeletonGraphicComp.material:SetFloat("_Blend",1.1)
                    resMgr:LoadSpritePrefab("Noise_016",function(tex)
                        _skeletonGraphicComp.material:SetTexture("_DissolveTex",tex.texture)
                        local blendNum = 1.1
                        setFadeTimeId = utimer.frameCall(function()
                            if blendNum > 0.055 then
                                _skeletonGraphicComp.material:SetFloat("_Blend",blendNum)
                                blendNum = blendNum - 0.055
                            else
                                objModel[index]:GetComponent("SkeletonGraphic").material = drawMat
                                utimer.remove(setFadeTimeId)
                                setFadeTimeId = nil
                            end
                        end,20)
                    end)
                end--]]
                if this.fadeTimeId then
                    utimer.remove(this.fadeTimeId)
                    this.fadeTimeId = nil
                end
                if this.fadeTimeIdNext then
                    utimer.remove(this.fadeTimeIdNext)
                    this.fadeTimeIdNext = nil
                end
                if isAnim then
                    if objModel[index] then
                        this.fadeTimeId = FadeFuc(objModel[index],1,10,nil,function(temp)
                            Util.Lua_SetLocalPositionXYZ(objModel[index].transform, tempPos.x+tempNum*temp, tempPos.y, tempPos.z)
                        end)
                    end
                    if objModel[4-index] then
                        this.fadeTimeIdNext = FadeFuc(objModel[4-index],0,5,function()
                            if objModel[4-index] ~= nil then
                                destroyImmediate(objModel[4-index]);
                                objModel[4-index] = nil
                            end
                        end,function(temp)
                            if objModel[4-index] then
                                local trans = objModel[4-index].transform
                                Util.Lua_SetLocalPositionXYZ(objModel[4-index].transform, trans.localPosition.x+tempNum*temp, trans.localPosition.y, trans.localPosition.z)
                            end
                        end)
                    end
                else
                    if objModel[4-index] ~= nil then
                        destroyImmediate(objModel[4-index]);
                        objModel[4-index] = nil
                    end
                end
            end,true);
        end
    end
    this.HeroLineTextController:SetSelectedIndex(0)
end

function UICharactorInfoHero.startShowDraw()
    local model = objModel[this.drawIndex];
    if model == nil or not this.canClickHero then
        return ;
    end
    if idleTimer ~= nil then
        idleTimer:Stop();
    end
    local g = model:GetComponent("SkeletonGraphic")
    g.AnimationState:SetAnimation(0, "idle2", false);

    local idleAniTime = g.AnimationState.Data.SkeletonData:FindAnimation("idle2").Duration;
    if idleTimer == nil then
        idleTimer = Timer.New(this.delayIdle, idleAniTime, 1, false);
    else
        idleTimer:Reset(this.delayIdle, idleAniTime, 1, false);
    end
    this.canClickHero = false;
    idleTimer:Start();

end

function UICharactorInfoHero.setPreviewMode(isPreviewMode)
    local select = isPreviewMode and 1 or 0
    ctrlShowBigDraw.selectedIndex = select

    if curShowSubPanelName ~= nil then
        if isPreviewMode then
            closeUI(curShowSubPanelName);
        else
            showUI(curShowSubPanelName, currentHeroData.partnerId);
        end
    end
end

function UICharactorInfoHero.openSubPanel(panelName, btn)
    --切换左边页签时调用，关闭上一个面板，开启当前面板
    if curShowSubPanelName ~= nil and curShowSubPanelName ~= panelName then
        closeUI(curShowSubPanelName);
    end
    curShowSubPanelName = panelName;
    if curShowSubPanelName ~= nil then
        if curShowSubPanelName == PanelNames.UICharactorInfoHeroBreak then
            closeUI(PanelNames.UICharactorInfoHeroBreak)
        end
        if curShowSubPanelName == PanelNames.UICharactorInfoHeroFavor then
            closeUI(PanelNames.UICharactorInfoHeroFavor)
        end
        if curShowSubPanelName == PanelNames.UICharactorInfoHeroRune then
            closeUI(PanelNames.UICharactorInfoHeroRune)
        end
        showUI(curShowSubPanelName, currentHeroData.partnerId, function(id)
            if id == PanelNames.UIHeroLink then
                logicMgr.HeroManager.setCharactorParameter(currentHeroData, 0, this.isShowOneHero, this.callback, heroType, this.jumpFun, this.sortType);
                this.onClickBack();
                showUI(PanelNames.UIHeroLink, nil, true);
            else
                log("onClickBack  " .. tostring(panelName))
                this.onClickBack();
                if this.jumpFun then
                    this.jumpFun();
                end
            end
        end, this.isShowOneHero);
    end
end
--- 属性
function UICharactorInfoHero.onClickAttribute()
    logicMgr.HeroManager.ClerPool()
    lasTabState = ButtonType.Attr
    this.openSubPanel(PanelNames.UICharactorInfoHeroAttribute, btnInfo);
    ctrlBottom.selectedIndex = lasTabState
    this.refreshShowIcon()
    --if this.cacheIsShowModel ~= isShowModel then
    isShowModel = this.cacheIsShowModel
    refreshView()
    --end
end
--技能
function UICharactorInfoHero.onClickSkill()
    logicMgr.HeroManager.ClerPool()
    lasTabState = ButtonType.Skill
    this.openSubPanel(PanelNames.UICharactorInfoHeroSkill, btnSkill);
    ctrlBottom.selectedIndex = lasTabState
    if isShowModel ~= true then
        this.cacheIsShowModel = isShowModel
        isShowModel = true
        refreshView()
    end
end
--- 装备
function UICharactorInfoHero.onClickEquip()
    log("onClickEquip")
    logicMgr.HeroManager.ClerPool()
    if logicMgr.FuncOpenManager.isOpen(Config.FuncOpenType.HeroEquip, true, btnEquip) then
        this.openSubPanel(PanelNames.UICharactorInfoHeroEquip, btnEquip);
        lasTabState = ButtonType.Equip
        --if this.cacheIsShowModel ~= isShowModel then
        isShowModel = this.cacheIsShowModel
        refreshView()
        --end
    end
    ctrlBottom.selectedIndex = lasTabState
end
---专武
function UICharactorInfoHero.onClickWeapon()
    logicMgr.HeroManager.ClerPool()
    -- 已经开启才做操作
    if logicMgr.FuncOpenManager.isOpen(Config.FuncOpenType.HeroWeapon, true, btnWeapon, { heroId = currentHeroData.partnerId }) then
        this.openSubPanel(PanelNames.UIWeapon);
        lasTabState = ButtonType.Weapon
        --if this.cacheIsShowModel ~= isShowModel then
        isShowModel = this.cacheIsShowModel
        refreshView()
        --end
    end
    ctrlBottom.selectedIndex = lasTabState
end
---突破
function UICharactorInfoHero.OnClickBreak()
    logicMgr.HeroManager.ClerPool()
    -- TODO WG 临时关闭
    if logicMgr.FuncOpenManager.isOpen(Config.FuncOpenType.HeroRank, true, btnBreak) then
        lasTabState = ButtonType.Break
        this.openSubPanel(PanelNames.UICharactorInfoHeroBreak);
        ctrlBottom.selectedIndex = lasTabState
        --if this.cacheIsShowModel ~= isShowModel then
        isShowModel = this.cacheIsShowModel
        refreshView()
        --end
    end
    ctrlBottom.selectedIndex = lasTabState
end
function UICharactorInfoHero.OnClickRune()
    logicMgr.HeroManager.ClerPool()
    if logicMgr.FuncOpenManager.isOpen(Config.FuncOpenType.Rune, true, btnRune) then
        lasTabState = ButtonType.Rune
        this.openSubPanel(PanelNames.UICharactorInfoHeroRune);
        isShowModel = this.cacheIsShowModel
        refreshView()
    end
    ctrlBottom.selectedIndex = lasTabState
end
---好感
function UICharactorInfoHero.OnClickFavor()
    logicMgr.HeroManager.ClerPool()
    this.openSubPanel(PanelNames.UICharactorInfoHeroFavor);
    --if this.cacheIsShowModel ~= isShowModel then
    isShowModel = this.cacheIsShowModel
    refreshView()
    --end
    lasTabState = ButtonType.Favor
    ctrlBottom.selectedIndex = lasTabState
end
function UICharactorInfoHero.onClickModelSwitch()
    isShowModel = not isShowModel;
    this.cacheIsShowModel = isShowModel;
    this.refreshView();
end

function UICharactorInfoHero.onClickPreview()
    bg.visible = false;
    orPosX, orPosY = graphicList[this.drawIndex].x, graphicList[this.drawIndex].y
    this.setPreviewMode(true);
    Input.multiTouchEnabled = true
    btnShare.visible = false
end

function UICharactorInfoHero.onClickPreviewBack()
    bg.visible = true;
    graphicList[this.drawIndex].x, graphicList[this.drawIndex].y = orPosX, orPosY
    graphicList[this.drawIndex].scaleX = 1
    graphicList[this.drawIndex].scaleY = 1
    this.setPreviewMode(false);
    Input.multiTouchEnabled = false
    btnShare.visible = true
end

function UICharactorInfoHero.GetLeftORRightHeroIndex(isLeft)
    local index = 0
    for i = 1, #allHero do
        if allHero[i]["partnerModelId"] == currentHeroData["partnerModelId"] then
            index = i;
            break ;
        end
    end
    if isLeft then
        index = index - 1;
        if index < 1 then
            index = #allHero;
        end
    else
        index = index + 1;
        if index > #allHero then
            index = 1;
        end
    end
    return allHero[index];
end

function UICharactorInfoHero.onClickLeftSwitch()
    if objModel[ModelType.hero] ~= nil then
        objModel[ModelType.hero]:SetActive(false)
        destroy(objModel[ModelType.hero]);
        objModel[ModelType.hero] = nil
        this.cur_show_model1 = nil
    end
    logicMgr.HeroManager.ClerPool()
    this.checkStopVoice()
    currentHeroData = this.GetLeftORRightHeroIndex(true)
    this.checkShowSkinBtn()
    this.refresh();
    this.refreshView(true,true)
    this.refreshShowIcon()
    isPlaySkillEffect = false
    this.reSkillGetData()
    this.openSubPanel(curShowSubPanelName);
    this.refreshManor();
end

function UICharactorInfoHero.onClickRightSwitch()
    if objModel[ModelType.hero] ~= nil then
        objModel[ModelType.hero]:SetActive(false)
        destroy(objModel[ModelType.hero]);
        objModel[ModelType.hero] = nil
        this.cur_show_model1 = nil
    end
    logicMgr.HeroManager.ClerPool()
    this.checkStopVoice()
    currentHeroData = this.GetLeftORRightHeroIndex()
    this.checkShowSkinBtn()
    this.refresh();
    this.refreshView(true)
    this.refreshShowIcon()
    isPlaySkillEffect = false
    this.reSkillGetData()
    this.openSubPanel(curShowSubPanelName);
    this.refreshManor();
end

function UICharactorInfoHero.onClickBack()
    utimer.remove(this.callBackId)
    logicMgr.HeroManager.ClerPool()
    this.openSubPanel(nil);
    closeUI(PanelNames.UICharactorInfoHero);
    if this.callback then
        this.callback();
    end
end

function UICharactorInfoHero.onClickArchives()
    this.checkStopVoice()
    if logicMgr.FuncOpenManager.isOpen(Config.FuncOpenType.HeroArchive, true) then
        AudioManager.Play(AudioManager.Play_UI_Hero_File_Page)
        showUI(PanelNames.UICharactorInfoArchives, currentHeroData);
    end
end

function UICharactorInfoHero.OnMoveStart(evt)
    startDragPosX = evt.inputEvent.x;
end

function UICharactorInfoHero.OnEndMove(evt)
    if evt then
        local endX = evt.inputEvent.x;
        if endX and startDragPosX then
            if endX > startDragPosX and math.abs(endX - startDragPosX) > 100 then
                this.onClickLeftSwitch();
            elseif startDragPosX > endX and math.abs(startDragPosX - endX) > 100 then
                this.onClickRightSwitch();
            end
        end
    end
end

function UICharactorInfoHero.HeroAcyion()
    if not this.isShowModel then
        this.startShowDraw();
    end
    --英雄界面点击角色1
    --查看解锁信息
    local _partnerModelId = this.currentHeroData["partnerModelId"]
    local _skinId = 0
    local _click1 = AudioManager.InteractionTagTable[6].Tag
    local _click2 = AudioManager.InteractionTagTable[7].Tag
    local _click3 = AudioManager.InteractionTagTable[8].Tag
    local _interactionInfo2 = G.dataTable["t_interaction"][_partnerModelId .. _skinId .. _click2]
    local _interactionInfo3 = G.dataTable["t_interaction"][_partnerModelId .. _skinId .. _click3]
    local _star = HeroManager.GetHeroStar(this.currentHeroData.partnerId)
    local count = 1
    if _interactionInfo2 and _interactionInfo2.f_UnlockCondition and _star >= _interactionInfo2.f_UnlockCondition[2] then
        if _interactionInfo3 and _interactionInfo3.f_UnlockCondition and _star >= _interactionInfo3.f_UnlockCondition[2] then
            count = 3
        else
            count = 2
        end
    end
    --随机一句话
    local _index = Mathf.Random(1, count)
    local _talkLevel = 0
    local _interactionTag
    if _index == 2 then
        _interactionTag = _click2
        _talkLevel = 1
    elseif _index == 3 then
        _interactionTag = _click3
        _talkLevel = 2
    else
        _interactionTag = _click1
        _talkLevel = 0
    end
    this.checkStopVoice()

    local _controllerIndex = 0
    local _skinId = 0
    local _interactionId = _partnerModelId .. _skinId .. _interactionTag
    local _interactionInfo = G.dataTable["t_interaction"][tostring(_interactionId)]
    if _interactionInfo and this.HeroLineTextController.selectedIndex == 0 and lasTabState ~= ButtonType.Weapon then
        if not string.IsNilOrEmpty(_interactionInfo.f_LineText) then
            local _introStr = getLanguage(_interactionInfo.f_LineText)
            if not string.IsNilOrEmpty(_introStr) then
                _controllerIndex = 1
                this.heroInteractionTipsNum = true;
                this.Txt_ActorLines.text = _introStr
            end
        end
    end
    this.HeroLineTextController:SetSelectedIndex(_controllerIndex)

    AudioManager.SetRTPCValue("talk_level", _talkLevel)
    AudioManager.PlayInteractionVoice(_partnerModelId, 0, _interactionTag)
end
function UICharactorInfoHero.checkStopVoice()
    AudioManager.TryStopInteractionVoice()
end

function UICharactorInfoHero.FashShow()
    showUI(PanelNames.UIHeroFashionShow, currentHeroData)
end

function UICharactorInfoHero.CloseHeroTips()
    if not this.heroTipsNum then
        this.heroTipsController.selectedIndex = 0;
    else
        this.heroTipsNum = false;
    end
    if not this.heroInteractionTipsNum then
        this.HeroLineTextController.selectedIndex = 0;
    else
        this.heroInteractionTipsNum = false;
    end

end

function UICharactorInfoHero.AddCommentNum()
    this.comment_count = this.comment_count or 0
    this.comment_count = this.comment_count + 1
    if this.comment_count <= 0 then
        this.comment_num_controller:SetSelectedIndex(0)
    elseif this.comment_count < 99 then
        this.comment_num_controller:SetSelectedIndex(1)
        this.txt_comment_num.text = tostring(this.comment_count)
    else
        this.comment_num_controller:SetSelectedIndex(1)
        this.txt_comment_num.text = "99"
    end
end

function UICharactorInfoHero.UpdateCommentNum(msg)
    this.comment_num_controller:SetSelectedIndex(1)
    this.txt_comment_num.text = "99"
end

function UICharactorInfoHero.ShowHeroTips()
    this.heroTipsType.text = getLanguage("HeroTypeInfo_" .. currentHeroData.type);
    local text = "";
    for k, v in pairs(currentHeroData.collocationDescribe) do
        if k ~= 1 then
            text = text .. "\n";
        end
        text = text .. getLanguage(v);
    end
    this.heroTipsDescribe.text = text;
    this.heroTipsList:RemoveChildrenToPool()
    local HeadRectDrawItem = CtrlManager.GetCtrl(PanelNames.HeadRectDrawItem);
    for k, v in pairs(currentHeroData.collocationHero) do
        local item = this.heroTipsList:AddItemFromPool();
        local itemValue = {};
        local friendData = logicMgr.HeroManager.getHeroDatabyModelId(v, true);
        itemValue["partnerModelId"] = friendData.partnerModelId
        itemValue["star"] = friendData.star;
        itemValue["type"] = friendData.type;
        if HeadRectDrawItem ~= nil then
            HeadRectDrawItem.initData(item, itemValue);
        end
    end
    this.heroTipsController.selectedIndex = 1;
    this.heroTipsNum = true;
    utimer.timeCall(function()
        this.heroTipsNum = false;
    end, 100, 1);
end

function UICharactorInfoHero.delayIdle()
    -- 调用loop的idea
    local model = objModel[this.drawIndex]
    if model ~= nil then
        this.canClickHero = true;
        if model:GetComponent("SkeletonGraphic").AnimationState then
            if model:GetComponent("SkeletonGraphic").AnimationState.Data.SkeletonData:FindAnimation("idle3") ~= nil then
                model:GetComponent("SkeletonGraphic").AnimationState:SetAnimation(0, "idle3", true);
            else
                model:GetComponent("SkeletonGraphic").AnimationState:SetAnimation(0, "idle1", true);
            end
        end
    end
end

function UICharactorInfoHero.refreshReward()
    local data = logicMgr.HeroManager.getHandbookByModelId(currentHeroData.partnerModelId, true);
    btnAward.visible = data ~= nil and not data.isReward;
    if data and not data.isReward then
        local heroData = HeroManager.getHeroDatabyModelId(currentHeroData.partnerModelId, true)
        if heroData then
            btnAward.title = string.format(getLanguage("HeroHello001"), heroData.name)
        end
    end
end

function UICharactorInfoHero.onClickReward()
    local data = logicMgr.HeroManager.getHandbookByModelId(currentHeroData.partnerModelId, true);
    if data ~= nil and not data.isReward then
        partnerHandler.sendHandbookReward(currentHeroData.partnerModelId);
    end
end
function UICharactorInfoHero.Fresh_HandbookRewardSuc(itemModelId, num)
    logicMgr.ItemFlyMgr.FlyDiamond(itemModelId, btnAward.xy)
end
function UICharactorInfoHero.checkShowSkinBtn()
    local data = HeroManager.SkinData(currentHeroData.partnerModelId)
    if #data > 1 then
        skinBtn.visible = true
    else
        skinBtn.visible = false
    end
end

function UICharactorInfoHero.wearNewSkin()
    this.refreshView()
end

function UICharactorInfoHero.onClickCombination()
    local info = HeroManager.getCombinationInfo()
    local showInfo = HeroManager.getCombinationShowInfo()
    local modelId = currentHeroData.partnerModelId;
    local combinationInfo = clone(showInfo[modelId]) or {};
    local combinationList = {}
    local combinationId = clone(combinationInfo.f_CombinationId)
    if combinationInfo and combinationInfo.f_CombinationId == nil then
        combinationInfo.f_CombinationId = {}
    end
    local isOpen = true;
    if combinationInfo == nil or (combinationInfo and table.getn(combinationInfo.f_CombinationId) == 0) then
        isOpen = false;
    end
    if combinationInfo.f_CombinationId2 ~= "" and combinationInfo.f_CombinationId2 ~= nil and table.getn(combinationInfo.f_CombinationId2) > 0 then
        table.insert(combinationId, combinationInfo.f_CombinationId2[1])
        if info[tostring(combinationInfo.f_CombinationId2[1])].f_Block ~= 1 then
            isOpen = true;
        else
            isOpen = false;
        end
    end
    if combinationId == nil then
        combinationId  = {};
    end
    for i, v in pairs(combinationId) do
        local param = {}
        param.skillId = v;
        if info[tostring(v)].f_Block ~= 1 and table.getn(info[tostring(v)].f_CombinationHero) > 0 then
            param.decs = info[tostring(v)].f_CombinationSkillDesc;--技能描述
            local heros = clone(combinationInfo.f_CombinationHero[i])
            table.insert(heros, 1, tonumber(modelId))
            param.heroIds = heros;
            param.type = 0; --普通英雄羁绊
            local isAdd = true;
            for i, v in pairs(param.heroIds) do
                if not logicMgr.HeroManager.isOpenHeroAtlas(v) then
                    isAdd = false;
                end
            end
            if isAdd then
                table.insert(combinationList, param);
                isOpen = true;
            end
        elseif info[tostring(v)].f_Block ~= 1 and table.getn(info[tostring(v)].f_CombinationHero) <= 0 then
            param.type = 1; --普通英雄羁绊
            param.decs = info[tostring(v)].f_CombinationSkillDesc;--技能描述
            param.decs2 = info[tostring(v)].f_CombinationDesc;--技能描述
            table.insert(combinationList, param);
            isOpen = true;
        end
    end
    if isOpen then
        showUI(PanelNames.UIHeroCombination, combinationList);
    else
        UISysTips.AddMsg(getLanguage("ErrorCode_230005"));
    end
end

function UICharactorInfoHero.onClickFavorHelp()
    logicMgr.UIShowManager.ShowCommonTips("HelpTitle48", "HelpDes48", "FunctionStory9005");
end

function UICharactorInfoHero.refreshManor()
    if logicMgr.HeroManorManager.isManorMaster(this.currentHeroData["partnerId"]) then
        heroManorCtrl.selectedIndex = 1;
    else
        heroManorCtrl.selectedIndex = 0;
    end
end

function UICharactorInfoHero.onClick_Manor()
    local cityInd, index = logicMgr.HeroManorManager.getMasterCityIdAndIndex(this.currentHeroData["partnerId"]);
    if cityInd ~= nil then
        showUI(PanelNames.UIHeroManor, cityInd, index);
    end
end

return UICharactorInfoHero;
